<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class FileExtension implements Rule
{

    protected $allowedExtensions = ['doc', 'docx']; // 设置允许上传的文件后缀名列表
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        //

        return in_array(strtolower(pathinfo($value, PATHINFO_EXTENSION)), $this->allowedExtensions);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return '只能上传 doc、docx 格式的文件';
    }
}
